// 拖拽移出
const VDragLeave = {
  name: 'dragleave',
  mounted: (el, binding) => {
    let timer
    const leaveHandler = (event) => {
      if (timer) {
        clearTimeout(timer)
      }
      timer = setTimeout(() => {
        const relatedTarget = event.relatedTarget
        if (!relatedTarget || !el.contains(relatedTarget)) {
          binding.value(event)
        }
      }, 10)
    }
    el.addEventListener('dragenter', (event) => {
      if (timer) {
        clearTimeout(timer)
      }
    })
    el.addEventListener('dragleave', leaveHandler)

    // 清理工作
    el.$onUnbind = function () {
      el.removeEventListener('dragleave', leaveHandler)
    }
  },
}

export default VDragLeave
